package com.redisdemo.controller;

import com.redisdemo.common.RedisConstant;
import com.redisdemo.domain.Student;
import com.redisdemo.utlis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <h3>redisDemo</h3>
 * <p></p>
 *
 * @author gdw
 * @since 2024-06-25 14:43:55
 */
@RestController
@RequestMapping("/index")
public class HelloController {
    @Autowired
    private RedisUtils redisUtils;

    /**
     * 获取redis中所有的key的值
     * @return
     */
    @GetMapping("/demo")
    public  Map<String,Object> demo(){
        Map<String,Object> o = (Map<String, Object>) redisUtils.getByPattern("uoso:dict::*");
        System.out.println(o);
        return o;
    }

    /**
     * 往arrlist集合中添加元素，模仿消息队列
     * @param
     * @return
     */
    @GetMapping("/savaLList")
    public Student savaLList(){
        String[] name={"小古"};
        Student student = Student.builder().name("小古").age(18).sex("男").build();
        redisUtils.lSet(RedisConstant.REDIS_LIST_ARRAYLIST, student);
        //添加成功后，返回给浏览器
        Student o = (Student) redisUtils.lGetRight(RedisConstant.REDIS_LIST_ARRAYLIST);
        return o;
    }


}
